package com.fuja.fumo;
import org.apache.log4j.Logger;

import com.fuja.fumo.ui.UIQuestion;
import com.fuja.fumo.ui.UISelect;
import com.fuja.swf.ui.UIUtil;

import waba.fx.Color;
import waba.sys.*;
import waba.ui.*;
/**
 * @see superwaba.samples.app.sales.Sales
 * @see com.fuja.fumo.FumoTest
 * @author marcelo_adamatti
 *
 */
public class Fumo extends MainWindow {
	private static Logger log = Logger.getLogger(Fumo.class);
	public static Fumo instance;
	private Window window;
	private MenuBar mnuBar;
	public Fumo(){
		super("FUMO - Fuja Mock",TAB_ONLY_BORDER);
		Vm.disableDebug = Settings.onDevice;		
		log.debug("Started in " + Settings.platform);
		
		instance = this;		
		setDoubleBuffer(true);		
		setStyle();
		
		mnuBar = buidMenu();
	    setMenuBar(mnuBar);
	}
	private void setStyle(){
		Settings.setUIStyle(waba.sys.Settings.Flat);
		UIColors.messageboxBack  = Color.BLUE;
		Button.commonGap = 1;
	}
	public void onStart(){
		try {
			window = new UISelect();
			UIUtil.swap(window);
						
		}catch(Exception e){
			e.printStackTrace();
			exit(0);
		}
	}
	private MenuBar buidMenu(){
		MenuItem[][] menu = new MenuItem[][]{
    		new MenuItem[]{
    			new MenuItem("File"),
    			new MenuItem("Select"),
    			new MenuItem("Exit")
    		},
    		new MenuItem[]{
    			new MenuItem("Tools"),
    			new MenuItem("Graph"),
    			new MenuItem("Export")
    		},
    		new MenuItem[]{
        		new MenuItem("Help"),
        		new MenuItem("Enable log"),
        		new MenuItem("About")
        	}
		};
		
	 	return new MenuBar(menu);
	}	
	public void onEvent(Event e) {
		if ((e.target==mnuBar) && (e.type==ControlEvent.PRESSED)){
			UIQuestion window;
			switch(mnuBar.getSelectedMenuItem() ){
				case -1: //out focus
					break;
				case 1:
					UIUtil.swap(new UISelect());
					break;
				case 2: //exit
					super.exit(0);
					return;
				case 101: //Graph					
					if (!(UIUtil.getActual() instanceof UIQuestion)) {					
						UIUtil.showMsg("Error","You need be in a Test");
						break;
					}					
					window = (UIQuestion)UIUtil.getActual();
					window.showGraph();
					break;
				case 102: //Export
					if (!(UIUtil.getActual() instanceof UIQuestion)) {					
						UIUtil.showMsg("Error","You need be in a Test");
						break;
					}					
					window = (UIQuestion)UIUtil.getActual();
					window.showExport();
					break;
				case 201:
					Vm.disableDebug = !Vm.disableDebug;
					break;
				case 202: //About
					UIUtil.showMsg("Fumo v0.1","FUMO - Fuja Mock|fumo-dev@fuja.dev.java.net||http://fumo.dev.java.net|http://fuja.dev.java.net");
					break;
				default:
					UIUtil.showMsg("Menu Debug",mnuBar.getSelectedMenuItem() + " selected!");
			}
		}
	}
}
